<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设备报修审批</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <style type="text/css">
        .left-label {
            width: 120px !important
        }
    </style>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
        <%--<input class="layui-input" name="searchTime" id="searchTime" placeholder="请输入时间检索" style="display: inline; width: 45%">--%>
        <input class="layui-input" name="keyword" id="keyword" placeholder="请输入设备名称" autocomplete="off" style="display: inline; width: 170px">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">搜索</i></button>
</div>
<table class="layui-hide" id="tableList" lay-filter="tableList"></table>

<script type="text/html" id="rowToolbar">
    {{#  if(d.approvalStatus == 0){ }}
        <a class="layui-btn layui-btn-xs" lay-event="pass">通过</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="back">驳回</a>
    {{#  } }}
</script>

<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<script type="text/javascript">
    //获取当前时间
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    var nowDate = year + "-" + month + "-" + day;
</script>
<script type="text/javascript">
    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;

        var $ = layui.jquery, active = {
            reload:function () {
                /*var searchTime = $("#searchTime").val();*/
                var keyword01 = $("#keyword").val();
                /*console.log(searchTime + ',' + keyword)*/
                table.reload('contenttable',{
                    method:'get',
                    where:{"keyword01":keyword01},
                    page: {
                        curr: 1
                    }
                });
            }
        }
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.render({
            elem: '#tableList'
            ,url:'${pageContext.request.contextPath }/breakdown/queryDeviceBreakdownApproval.do'
            ,toolbar: '#toolbar'
            ,title: '设备维修申请审批'
            ,id :'contenttable'
            ,limits:[10,20,30]
            ,cols: [[
                {type: 'checkbox', fixed: 'left', },
                {field:'', title:'序号', sort: true, type:'numbers', width: 60},
                {field:'deviceName', title:'设备编号'},
                {field:'deviceNo', title:'故障设备名称'},
                {field:'repairDept', title:'报修部门/车间'},
                {field:'repairMan', title:'报修人'},
                {field:'repairTime', title:'报修时间'},
                {field:'errorDescribe', title:'故障现象描述'},
                {field:'approvalStatus', title:'审批状态', templet: function(row){
                    if(row.approvalStatus == '1'){
                        return '审批通过';
                    } else if (row.approvalStatus == '2') {
                        return '驳回';
                    } else {
                        return '未审批';
                    }
                }},
                {field:'approvalOpinion', title:'意见'},
                {fixed:'right', title:'操作', toolbar: '#rowToolbar', width: 150}
            ]],
            page: true
        });

        //监听行工具事件
        table.on('tool(tableList)', function(obj){
            var data = obj.data;
            //单个删除
            if(obj.event === 'approval'){
                layer.open({
                    type: 1 						//Page层类型
                    ,area: ['500px', '200px']		//宽  高
                    ,title: '审批'
                    ,shade: 0.6 					//遮罩透明度
                    ,maxmin: true 					//允许全屏最小化
                    ,anim: 1 						//0-6的动画形式，-1不开启
                    ,content: '<form class="layui-form" id="editFormID">'+
                                '<input class="layui-hide" id="id" name="id" value="'+data.id+'">'+
                                '<label class="layui-form-label left-label">审批意见</label><input class="layui-input" id="approvalOpinion" name="approvalOpinion" style="width:300px; margin-top:15px"><br>'+
                                '<button class="layui-btn layui-btn-blue" lay-submit lay-filter="editForm1" style="margin-left:160px; margin-bottom: 20px">提交</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button>'+
                              '</form>'
                });
            } else if (obj.event === 'pass') {
                layer.open({
                    type: 1 						//Page层类型
                    ,area: ['500px', '200px']		//宽  高
                    ,title: '审批'
                    ,shade: 0.6 					//遮罩透明度
                    ,maxmin: true 					//允许全屏最小化
                    ,anim: 1 						//0-6的动画形式，-1不开启
                    ,content: '<form class="layui-form" id="editFormID">'+
                        '<input class="layui-hide" id="id" name="id" value="'+data.id+'">'+
                        '<label class="layui-form-label left-label">通过意见</label><input class="layui-input" id="approvalOpinion" name="approvalOpinion" style="width:300px; margin-top:15px"><br>'+
                        '<button class="layui-btn layui-btn-blue" lay-submit lay-filter="editForm1" style="margin-left:160px; margin-bottom: 20px">提交</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button>'+
                        '</form>'
                });
            } else if (obj.event === 'back') {
                layer.open({
                    type: 1 						//Page层类型
                    ,area: ['500px', '200px']		//宽  高
                    ,title: '审批'
                    ,shade: 0.6 					//遮罩透明度
                    ,maxmin: true 					//允许全屏最小化
                    ,anim: 1 						//0-6的动画形式，-1不开启
                    ,content: '<form class="layui-form" id="editFormID">'+
                        '<input class="layui-hide" id="id" name="id" value="'+data.id+'">'+
                        '<label class="layui-form-label left-label">驳回意见</label><input class="layui-input" id="approvalOpinion" name="approvalOpinion" style="width:300px; margin-top:15px"><br>'+
                        '<button class="layui-btn layui-btn-blue" lay-submit lay-filter="editForm2" style="margin-left:160px; margin-bottom: 20px">提交</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button>'+
                        '</form>'
                });
            }
        });

        /**
         * 通用表单提交(AJAX方式)(审批)
         */
        form.on('submit(editForm1)', function (data) {
            $.ajax({
                url : '${pageContext.request.contextPath}/breakdown/updateApprovalStatusById.do',
                data: $("#editFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('审批成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('审批失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });

        /**
         * 通用表单提交(AJAX方式)(驳回)
         */
        form.on('submit(editForm2)', function (data) {
            $.ajax({
                url : '${pageContext.request.contextPath}/breakdown/updateApprovalStatusById2.do',
                data: $("#editFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('驳回成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('驳回失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });
    });

    toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上

    //提示框样式
    function toastrStyle(){
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "newestOnTop": false,
            "progressBar": false,
            "positionClass": "toast-top-center",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "5000",
            "hideDuration": "1000",
            "timeOut&quot": "100000",
            "extendedTimeOut": "0",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
    }

</script>
</body>
</html>